// 搭配vant的轻提示二次封装
import {
  showLoadingToast,
  showToast,
  showSuccessToast,
  showFailToast,
  closeToast,
} from "vant";

/**
 * 基于 vant4 的 toast 方法进行二次封装
 * @author Matcha <gn13342725221@outlook.com>
 * @param {'Loading'|'show'|'success'|'fail'|'close'} type 提示类型
 * @param {object} [obj] 对应 toast 组件中传入的对象
 * @param {string} obj.msg 提示信息
 * @param {'bottom'|'top'|'center'} obj.position 提示的位置
 * @param {object} obj.onClose 提示关闭时的回调
 * @param {boolean} obj.forbidClick 提示期间是否屏蔽背景点击
 * @param {0|1} obj.duration 是否一直显示提示 0为是，1为否
 * @param {string} obj.icon 提示中展示的图标
 * @example
 * ToastFun('Loading', { duration: 1000 })
 */
export const ToastFun = (type, obj = {}) => {
  let { msg, position, onClose, forbidClick, duration, icon } = obj;

  if (type == "Loading") {
    showLoadingToast({
      onClose,
      duration,
      position,
      message: msg,
      forbidClick: true,
    });
  } else if (type == "show") {
    showToast({
      icon,
      position,
      forbidClick,
      message: msg,
    });
  } else if (type == "success") {
    showSuccessToast(msg);
  } else if (type == "hotelOrderSuccess") {
    showSuccessToast("未支付订单提交成功");
  }
  else if (type == "hotelOrderFail") {
    showFailToast("请设置入住时间");
  }
  else if (type == "hotelPayFail") {
    showFailToast("支付失败");
  }
  else if (type == "hotelPaySuccess") {
    showSuccessToast("支付成功");
  }
  else if (type == "fail") {
    showFailToast(msg);
  } else if ((type = "close")) {
    closeToast();
  }
};
